package com.mobile.common.base.handler;

import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.mobile.common.base.hibernate.SimpleDao;

@Transactional
@SuppressWarnings("rawtypes")
public abstract class BaseHandler<T , PK extends Serializable> {

	
	public BaseHandler() {}

	public abstract SimpleDao<T, PK> getEntityDao();
	
	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public T get(Long id){
		return (T)getEntityDao().get(id);
	}
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public Object load(Long id){
		return getEntityDao().load(id);
	}
	public void save(Object obj){
		getEntityDao().save(obj);
	}
	public void destroy(Object...objs){
		for(Object obj : objs)
			getEntityDao().destroy(obj);
	}
	public void destory(Long...ids){
		for(Long id : ids)
			getEntityDao().destroy(id);
	}
	public void merge(Object obj){
		getEntityDao().merge(obj);
	}
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public List findByProperty(String propertyName, Object value){
		return getEntityDao().findBy(propertyName, value);
	}
}
